// src/components/JsonViewer.tsx
import React from 'react';
import { Typography, Collapse } from 'antd';
import ReactJson from 'react-json-view'
const { Panel } = Collapse;

interface JsonViewerProps {
  json: any;
}

const JsonViewer: React.FC<JsonViewerProps> = ({ json }) => {
  let jsonObj = {}
  try {
    jsonObj = typeof json === 'string' ? JSON.parse(json) : json;
  } catch (e) {
    jsonObj = json;
  } 
  if(typeof jsonObj === 'string'){
    return <Typography.Text>{jsonObj}</Typography.Text>;
  }
  return <ReactJson src={jsonObj} collapsed={true} name={null} displayDataTypes={false} displayObjectSize={false} />;
};

export default JsonViewer;